package com.purchase.ml.resource.dealer;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.purchase.ml.annotations.OperLog;
import com.purchase.ml.bean.base.ApiRestResult;
import com.purchase.ml.bean.req.dealer.DealerCategoryEditDto;
import com.purchase.ml.bean.req.dealer.DealerCategoryQueryDto;
import com.purchase.ml.consts.PermissionsConst;
import com.purchase.ml.entity.prod.SysCategory;
import com.purchase.ml.service.prod.SysCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author :zxm
 * @date :2021/3/9 16:01
 * @description :some description
 **/
@RestController
@RequestMapping("/dealer_category/")
@Slf4j
@Api(tags = "经销商产品目录")
public class DealerCategoryResource {

    @Autowired
    private SysCategoryService categoryService;

    @PostMapping("/query")
    @ApiOperation("分页查询主经销商产品目录")
    @RequiresPermissions(PermissionsConst.CATGORY_QUERY)
    public ApiRestResult dealerCategoryQuery(@RequestBody DealerCategoryQueryDto queryDto){
        IPage<SysCategory> pageResult = categoryService.dealerCategoryQuery(queryDto);
        return ApiRestResult.ok(pageResult);
    }

    @PostMapping("/edit")
    @ApiOperation("编辑主经销商产品目录")
    @OperLog(operDesc = "EditDealerCategory", operModul = "DealerCategory", operType = "Edit")
    @RequiresPermissions(PermissionsConst.CATGORY_EDIT)
    public ApiRestResult editDealerCategory(@RequestBody @Valid DealerCategoryEditDto dealerCategoryEditDto){
        ApiRestResult rs = categoryService.editDealerCategory(dealerCategoryEditDto);
        return rs;
    }

}
